﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;

namespace VisualWebGuiApplication2
{
    [Serializable]
    public partial class InvoiceControlTankStockAdd : Form
    {
        Tank_Stocks selcted;
        GazOnDevEntities db;
        string CurrentAmount;
        
        public InvoiceControlTankStockAdd()
        {
            InitializeComponent();
            txtTankNumber.Leave += new EventHandler(txtTankNumber_Leave);
           db=new GazOnDevEntities();
           button1.Enabled = false;

              
              
                
            
        }

        void txtTankNumber_Leave(object sender, EventArgs e)
        {
            bool error = false;
        
                if(!string.IsNullOrEmpty(txtTankNumber.Text))
                {

                    selcted = db.Tank_Stocks.FirstOrDefault(x => x.TankNumber == txtTankNumber.Text);
                    if (null == selcted)
                    {
                        MessageBox.Show("לא קיים מספר צובר כזה ");
                        return;

                    }
                    if (!string.IsNullOrEmpty(selcted.invoiceid))
                    {
                        MessageBox.Show("צובר עם מספר זה  מקושר כבר לתעןדת משלוח  מס  " + selcted.invoiceid  );
                        return;
                    }
                    
                    if (selcted.Id < 1)
                  {
                      error = true;
                  }
                }else
                {
                    error = false;
                  
                
                }

                if (error)
                {
                    MessageBox.Show("לא קיים מספר צובר כזה ");
                }
                else
                {
                    button1.Enabled = true;
                    tankSize = selcted.Tank_Size.ToString();
                    labelSize.Text = selcted.Tank_Size.ToString();
                    tankID = selcted.Id.ToString();
                    TankNumber = selcted.TankNumber;
                    _Type = "tank";
                    _Typeid = selcted.Id.ToString();
                    _Amount = "1";
                
                    
                    
                }
        }

        





          public string tankID
          {
              get;

              set;

          }

        public string TankNumber
        {
            get ;
            
            set;
          
        }

        public string Note
        {
            get
            {
                return txtNote.Text;
            }
            set
            {
                txtNote.Text = value;
            }
        }

        public string tankSize
        {
            get;
            set;

        }
        public string _Type
        {
            get;
            set;

        }
        public string _Amount
        {
            get;
            set;

        }
        public string _Typeid
        {
            get;
            set;

        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            this.Close();

        }

     

    

     

    }
}